package com.client.ryt.config;


import android.content.SharedPreferences;

import com.client.ryt.basic.BaseApplication;
import com.client.ryt.entity.biz.ShopMember;


/**
 *
 * 登录配置.
 *
 * @author heyao
 */
public class LoginConfig {

    /***
     * 当前登录成功获取的token
     */
    private String token;
    private ShopMember shopMember;

    private LoginConfig(){ }
    public String getToken() {
        return token;
    }
    public void setToken(String token) {
        this.token = token;
    }

    public ShopMember getShopMember() {
        return shopMember;
    }

    public void setShopMember(ShopMember shopMember) {
        this.shopMember = shopMember;
    }

    public static void saveLoginConfig(LoginConfig loginConfig){
        SharedPreferences ps = BaseApplication.getInstance().getSharedPreferences(Constant.LOGIN_SET, 0);
        ps.edit()
                .putString(Constant.TOKEN,loginConfig.getToken()).commit();
        ps.edit()
                .putLong(Constant.UID, loginConfig.getShopMember().getUid()).commit();
        ps.edit()
                .putString(Constant.USERNAME,loginConfig.getShopMember().getUsername()).commit();
        ps.edit()
                .putString(Constant.USERNICKNAME,loginConfig.getShopMember().getNickname()).commit();
        ps.edit()
               .putLong(Constant.USERSHOPID,loginConfig.getShopMember().getShop_id()).commit();
        ps.edit()
               .putString(Constant.USERTOKEN,loginConfig.getShopMember().getToken()).commit();
        ps.edit()
                .putString(Constant.SHOPNAME,loginConfig.getShopMember().getShopname()).commit();
    }

    public static LoginConfig getLoginConfig() {
        SharedPreferences ps = BaseApplication.getContext().getSharedPreferences(Constant.LOGIN_SET, 0);
        LoginConfig loginConfig = new LoginConfig();
        loginConfig.setToken(ps.getString(Constant.TOKEN,null));
        ShopMember sm = new ShopMember();
        sm.setUid(ps.getLong(Constant.UID,0));
        sm.setUsername(ps.getString(Constant.USERNAME,null));
        sm.setNickname(ps.getString(Constant.USERNICKNAME,null));
        sm.setShop_id(ps.getLong(Constant.USERSHOPID,0));
        sm.setToken(ps.getString(Constant.USERTOKEN,null));
        sm.setShopname(ps.getString(Constant.SHOPNAME,null));
        loginConfig.setShopMember(sm);
        return loginConfig;
    }

    public static void clearToken(){
        SharedPreferences preferences = BaseApplication.getContext().getSharedPreferences(Constant.LOGIN_SET, 0);
        preferences.edit()
                .putString(Constant.TOKEN,null).commit();
    }
}
